<template>
    <div class="index clearafter">
        <div class="cbafter">
            <button class="default ok fr" @click="returndoclist">返回医生列表</button>
        </div>
        <table class="table cb table-bordered table-condensed">
            <tr>
                <th class="active" style="border-bottom:none">坐诊</th>
                <th class="active" v-for="item in datearr">{{item}}</th>
            </tr>
            <tr>
                <th class="active" style="border-top:none">时间</th>
                <th class="active" v-for="item in dayarr">{{item}}</th>
            </tr>
            <tr>
                <td class="active">上午</td>
                <td v-for="(index,item) in arr1" @click="planedit(item,index)" :class="{mscursor:!item.text}" track-by="$index">
                    <p v-show="!item.text">预约</p>
                </td>
            </tr>
            <tr>
                <td class="active">下午</td>
                <td v-for="(index,item) in arr2" @click="planedit(item,index)" :class="{mscursor:!item.text}" track-by="$index">
                    <p v-show="!item.text">预约</p>
                </td>
            </tr>
            <tr>
                <td class="active">晚上</td>
                <td v-for="(index,item) in arr3" @click="planedit(item,index)" :class="{mscursor:!item.text}" track-by="$index">
                    <p v-show="!item.text">预约</p>
                </td>
            </tr>
        </table>
        <!-- 就诊安排确认 -->
        <div class="modal fade" id="planconfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="myModalLabel">就诊安排确认</h4>
                    </div>
                    <div class="modal-body">
                        <div class="unit"><span>预约时间：</span>{{editdata.patientVisitPlan.planDate}}</div>
                        <div class="unit"><span>患者姓名：</span>{{patientname}}</div>
                        <div class="unit"><span>医生姓名：</span>{{editdata.patientVisitPlan.doctorName}}</div>
                        <div class="unit"><span>执业机构：</span>{{editdata.patientVisitPlan.orgName}}</div>
                        <div class="unit"><span>出诊科室：</span>{{editdata.patientVisitPlan.deptName}}</div>
                    </div>
                    <div class="modal-footer ">
                        <div class="buttongroup">
                            <button type="button" class="default blue center" @click="planconfirm">确定</button>
                            <button type="button" class="default center greynobg" @click="cancelplan">取消</button>
                        </div>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal -->
        </div>
    </div>
</template>
<script>
import Public from 'assets/public.js'
import {
    actions
}
from '../vuex/store';
module.exports = {
    vuex: {
        actions: actions,
        getters: {
            arr1: (arrdata) => arrdata.arr1,
            arr2: (arrdata) => arrdata.arr2,
            arr3: (arrdata) => arrdata.arr3,
            datearr: (arrdata) => arrdata.datearr,
            doctorName:(arrdata) => arrdata.doctorName,
        doctorphoneNo:(arrdata) => arrdata.doctorphoneNo,
        dayarr:(arrdata) => arrdata.dayarr,
        }
    },
    data() {
        return {
           
            // dayarr: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'], //星期数组固定死
            editdata: {
                "mpiId": "",
                "serviceId": "22b95c65-c1ab-11e6-a12c-005056a40280",
                "patientVisitPlan": {
                    "orgId": "",
                    "orgName": "",
                    "deptId": "",
                    "deptName": "",
                    "doctorId": "",
                    "doctorName": "",
                    "planDate": "", //排班日期
                    "planClass": "", //班次
                    "operateUserType": "081", //APP传041且不需要传mpiId,网页上传081,需要传mpiId
                    "operateUser": "", //APP传mpiId,网页传doctorID
                    "operateUserName": "", //APP传患者姓名,网页传doctorName
                    "phoneNo": "" //APP传患者手机,网页传doctorPhoneNo
                }
            }, //选中编辑的数据
            editdataindex: "", //选中编辑的数据在+或者arr2或者arr3的索引
        }
    },
    ready() {
        var that = this;
    },
    
    props: {
            mpiidtohdp: {
                type: String,
                default: ""
            },
            patientname: {
                type: String,
                default: ""
            },

        },
    methods: {

        returndoclist() {
                this.changeView("请选择医生");
            },
        planedit(item, index) { //点击表格td编辑排班
                if (!item.text) {
                    $("#planconfirm").modal("show");
                    item.doctorName=this.doctorName;
                    item.doctorphoneNo=this.doctorphoneNo;
                    item.operateUser=this.mpiidtohdp;
                    item.operateUserName=this.doctorName;
                    item.operateUserType="081";
                    item.planDate=item.planDate.substring(0,10);
                    this.editdata.patientVisitPlan = item;
                    this.editdata.mpiId=this.mpiidtohdp;
                    this.editdataindex = index
                }
        },
        //确认保存
        planconfirm() {
            var that=this;
            $.when(Public.commonajax("coms.doctorPlanService", "savePatientVisitPlan", "["+JSON.stringify(this.editdata)+"]")).done(function(res) {
               if(res.code==200){
                    Public.ajaxPrompt("预约成功");
                     $("#planconfirm").modal("hide");
                     that.$dispatch('planconfirmok')
               }else{
                 Public.ajaxPrompt("预约失败，请重新预约");
               }
            });
        },
        cancelplan() {
            $("#planconfirm").modal("hide");
        }


    },
    events: {

    },
}
</script>
<style scoped>
.table {
    margin-top: 30px;
}

.table td,
.table th {
    text-align: center;
}

.table th {
    font-weight: normal;
}

.table tr td.mscursor {
    background: #1dc499;
    color: #fff;
}

.table tr td.mscursor:hover {
    cursor: pointer;
}

.table tr td.active {
    color: #333
}

.table tr td.active:hover {
    color: #333;
    background: none
}

.table tr th:nth-child(1) {
    color: #1dc499
}

.unit {
    float: left;
    width: 42%;
    text-align: center;
    line-height: 30px;
    height: 30px;
    border-radius: 5px;
    margin: 10px 4%;
    color: #333;
    font-weight: bold;
}

.unit span {
    font-weight: normal;
}

#planconfirm .unit {
    float: none;
    width: 500px;
    padding-left:100px ;
    text-align: left
}

.buttongroup {
    width: 300px;
    margin: 10px auto;
}

.buttongroup button {
    display: inline-block;
}

.buttongroup button:nth-child(2) {
    margin-left: 30px
}
</style>
